package com.xzy.sms.web.system.service.security;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.realm.AuthorizingRealm;

import com.xzyframework.SpringContextHolder;

/**
 * shiro权限工具类
 * 
 * @author macong
 * @since 1.0
 * @version 2014-10-15 macong
 */
public class SecurityUtils {
    
    /** 域 */
    private static ShiroRealm shiroRealm;
    
    /**
     * 根据token值登录
     * 
     * @param userId userId
     * @param account account
     * @param name name
     * @return boolean
     */
    public static AuthenticationInfo getAuthInfo(String userId, String account, String name) {
        UserProfile up = new UserProfile(userId, account, name);
        AuthenticationInfo info = new SimpleAuthenticationInfo(up, "", null, getShiroRealm().getName());
        return info;
    }
    
    /**
     * @return OrgService
     */
    private static AuthorizingRealm getShiroRealm() {
        if (null == shiroRealm) {
            return SpringContextHolder.getBean(ShiroRealm.class);
        }
        return shiroRealm;
    }
}
